package cn.bonoon.kernel.descriptors.impl;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import cn.bonoon.kernel.descriptors.ObjectDescriptor;
import cn.bonoon.kernel.descriptors.ObjectPropertyAccessor;

public final class ObjectPropertyAccessorImpl extends MappablePropertyAccessor<ObjectPropertyAccessor, ObjectDescriptorImpl> implements ObjectPropertyAccessor{
	
	public ObjectPropertyAccessorImpl(ObjectDescriptorImpl objectDescriptorImpl, Field field) {
		super(objectDescriptorImpl, field);
	}
	
	private boolean invalid;
	
	/**
	 * 标志该属性在两个类之间进行传转换的时候，不进行处理，即需要排除掉
	 */
	public void invalid(){
		this.invalid = true;
	}
	
	public boolean isInvalid() {
		return invalid;
	}
	
	@Override
	public final Class<?> getActualType(){
		Type ty = field.getGenericType();
		if(ty instanceof ParameterizedType){
			ParameterizedType pt = (ParameterizedType)ty;
			Type[] ts = pt.getActualTypeArguments();
			if(ts.length > 0) return (Class<?>)ts[0];
		}
		return null;
	}
	
	@Override
	public ObjectDescriptor getDescriptor() {
		return classDescriptor;
	}
}
